import {iMicroApp} from "@peryl/micro-web";
import {MicroAppModule} from "./MicroAppModule";
import {defer} from "@peryl/utils/defer";

export const microAppDefer = MicroAppModule.createRegistration((option) => {
  const ret: iMicroApp['defer'] = {
    /**
     * loadMicroInfoMap和loadMicroReadyMap的类型都是 Record<string, DFD>，FrameModeFrame以及FrameModeNone在加载得到Win,
     * subRoutePublicPath以及mainConfig的时候调用执行这个loadMicroInfoMap[microConfig.id].resolve，通知MicroItem先执行初始化逻辑，
     * MicroItem初始化完毕之后触发 loadMicroReadyMap[microConfig.id].resolve通知FrameModeFrame以及FrameModeNone执行子应用的初始化逻辑
     * @author  韦胜健
     * @date    2024.3.24 9:31
     */
    loadMicroInfoMap: {},
    loadMicroReadyMap: {},
    reset: (): void => {
      option.state.microConfigs.forEach(microConfig => {
        ret.loadMicroInfoMap[microConfig.id] = defer<any>();
        ret.loadMicroReadyMap[microConfig.id] = defer<any>();
      });
    },
  };
  return ret;
});
